package com.lanxiao.cloud.modules.file.controller;

import com.lanxiao.cloud.common.core.enums.OperationType;
import com.lanxiao.cloud.common.web.invalid.Log;
import com.lanxiao.cloud.modules.file.application.FileConfigureCmdManager;
import com.lanxiao.cloud.modules.file.application.FileConfigureQueryManager;
import com.lanxiao.cloud.modules.file.application.dto.FileConfigureCmdUpdate;
import com.lanxiao.cloud.modules.file.application.dto.FileConfigureDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：qiaoliang
 * @date ：2021-10-25
 */
@Api(tags = "文件服务")
@Validated
@RequestMapping("/file-configures")
@RestController
public class FileConfigureController {

  private final FileConfigureCmdManager fileConfigureCmdManager;
  private final FileConfigureQueryManager fileConfigureQueryManager;

  public FileConfigureController(
      FileConfigureCmdManager fileConfigureCmdManager,
      FileConfigureQueryManager fileConfigureQueryManager) {
    this.fileConfigureCmdManager = fileConfigureCmdManager;
    this.fileConfigureQueryManager = fileConfigureQueryManager;
  }

  @ApiOperation(value = "查询上传配置")
  @GetMapping
  public List<FileConfigureDto> all() {
    return fileConfigureQueryManager.all();
  }

  @ApiOperation(value = "修改上传配置")
  @Log(operationType = OperationType.UPDATE,
      serviceClass = FileConfigureQueryManager.class)
  @PutMapping("/{id}")
  public ResponseEntity<?> update(@PathVariable Long id, @RequestBody FileConfigureCmdUpdate update) {
    fileConfigureCmdManager.updateFileConfigure(id, update);
    return ResponseEntity.status(HttpStatus.PARTIAL_CONTENT).build();
  }

}
